/*
 * @Author: hua
 * @Date: 2020-07-17 17:03:32
 * @description: 
 * @LastEditors: hua
 * @LastEditTime: 2020-07-23 10:15:19
 */
import Cookies from 'js-cookie'
import { getProductionBatch } from '@/utils/auth'
const app = {
  state: {
    sidebar: {
      opened: !+Cookies.get('sidebarStatus'),
      withoutAnimation: false
    },
    device: 'desktop',
    productionBatch: getProductionBatch() ? getProductionBatch() : {
      creationDate: "",
      lastModifiedDate: null,
      id: 0,
      batchName: "",
      batchNumber: "",
      startDate: "",
      endDate: "",
      enable: 0
    },
    equipmentInfo: {
      shellQrCode: "",
      simcardImei: ""
    }
  },
  getters: {
    productionBatch(state) {
      return state.productionBatch
    },
    equipmentInfo(state) {
      return state.equipmentInfo
    }
  },
  mutations: {
    TOGGLE_SIDEBAR: state => {
      if (state.sidebar.opened) {
        Cookies.set('sidebarStatus', 1)
      } else {
        Cookies.set('sidebarStatus', 0)
      }
      state.sidebar.opened = !state.sidebar.opened
    },
    CLOSE_SIDEBAR: (state, withoutAnimation) => {
      Cookies.set('sidebarStatus', 1)
      state.sidebar.opened = false
      state.sidebar.withoutAnimation = withoutAnimation
    },
    TOGGLE_DEVICE: (state, device) => {
      state.device = device
    },
    SAVE_PRODUCTION_BARCH: (state, productionBatch) => {
      state.productionBatch = productionBatch
    },
    SAVE_EQUIPMENT_INFO: (state, equipmentInfo) => {
      state.equipmentInfo = equipmentInfo
    }
  },
  actions: {
    ToggleSideBar: ({ commit }) => {
      commit('TOGGLE_SIDEBAR')
    },
    CloseSideBar({ commit }, { withoutAnimation }) {
      commit('CLOSE_SIDEBAR', withoutAnimation)
    },
    ToggleDevice({ commit }, device) {
      commit('TOGGLE_DEVICE', device)
    }
  }
}

export default app
